home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7400 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: csus.edu!news
  2. From: wleong@sfsu.edu (Jerry Leong)
  3. Newsgroups: comp.lang.c
  4. Subject: Possible to use #define to define global variable?
  5. Date: Mon, 26 Feb 1996 02:39:09 GMT
  6. Organization: San Francisco State University
  7. Message-ID: <31311b97.1170723@news.csus.edu>
  8. NNTP-Posting-Host: wleong@pluto.sfsu.edu
  9. X-Newsreader: Forte Agent .99d/32.182
  10.  
  11. Hi,
  12.     I recently need to do programming that restrict the number of
  13. bytes in a structure. Knowing that it might not possible to turn off
  14. padding in the structure, I am now thinking if it is possible to use
  15. #define to define a global variable? That way, I can fix the size
  16. of my structure without worrying about the padding.
  17.  
  18.    Here's what I have in mind :
  19.  
  20.    Normally,
  21.                        struct MSG{
  22.                                   char   buffer[3];
  23.                                  };
  24.    sizeof(struct MSG) is 4 due the the padding on the structure.
  25.  
  26.    What if,
  27.                        #define  buffer char[3];
  28.   That might work, but than I couldn't assign anything to buffer due
  29. to the nature of #define.
  30.  
  31.    Is there anyway to work around this problem?
  32.  
  33. p/s: I am currently working on UNIX for this program. Thanx in advance
  34.  
  35.         for your responce.
  36.